Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add workaround for Swagger UI operation id wrapping #2891

Closed
wants to merge 1 commit into from

Conversation

cremor
Copy link
Contributor

@cremor cremor commented May 15, 2024

The issue or feature being addressed

Since Swashbuckle 6.6.0 updated from Swagger UI version 4.15.5 to 5.17.9 the operation ids (which are shown if app.UseSwaggerUI(c => c.DisplayOperationId()); is used) are wrapping even if there would be enough space. See swagger-api/swagger-ui#9577

Details on the issue fix or feature implementation

The workaround works, but I'm not sure if this is the best way to fix this. This is also why I didn't create a PR for Swagger UI directly.

I'm also not sure if this should really be added to Swashbuckle. But the index.html file already contains some other workarounds, so I guess it's fine?

I've tested the fix by using the SwaggerUIOptions.HeadContent property. But I'd like to test it with a real Swashbuckle package too. Is there a way to get a PR build published on the MyGet feed?

An alternative would be to modify the method DisplayOperationId instead. In there we could do this:

var builder = new StringBuilder(options.HeadContent);
builder.AppendLine("<style>.opblock-summary-operation-id { word-break: normal !important; }</style>");
options.HeadContent = builder.ToString();

I'm open for better ideas.

@martincostello
Copy link
Collaborator

Thanks for the suggestion, but as you noted I don't think this is a workaround we should build in and ship ourselves. Custom CSS can already be specified, so anyone affected by this could apply the workaround in their own code until it's fixed in Swagger UI itself.

@mesMess
Copy link
Collaborator

mesMess commented Jul 1, 2024

Closing this PR:

  • Library dependency (Swagger UI)
  • Custom CSS can be implemented on a case-by-case basis

@mesMess mesMess closed this Jul 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants